package jEDF.Dialog;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.border.*;

import jEDF.JEDF.*;
import projetotcc2.ProjetoTCC2View;

/**
 *
 * <p>Titre : jEDF</p>
 * <p>Description : Java European Data Format Viewer and Analyser</p>
 * <p>Author : Nizar Kerkeni</p>
 * <p>Copyright : Copyright (c) 2003-2006</p>
 * <p>Version 2.0</p>
 */
public class JEDFHelpDialog extends JDialog {

    String[] contentGInfo = {
        JEDFMainWindow.getLocalizedString("Go to the previous second"),
        JEDFMainWindow.getLocalizedString("Go to the next second"),
        JEDFMainWindow.getLocalizedString("Go to the beginning"),
        JEDFMainWindow.getLocalizedString("Go to the end")};
    String[] contentHInfo = {
        JEDFMainWindow.getLocalizedString("Awake"),
        JEDFMainWindow.getLocalizedString("Movement"),
        JEDFMainWindow.getLocalizedString("Stage 1 to 4"),
        JEDFMainWindow.getLocalizedString("REM"),
        JEDFMainWindow.getLocalizedString("Unscored")};
    String[] contentPSInfo = {
        JEDFMainWindow.getLocalizedString(
        "Go to the previous precise scoring label"),
        JEDFMainWindow.getLocalizedString(
        "Go to the next precise scoring label"),
        JEDFMainWindow.getLocalizedString("Set a custom label"),
        JEDFMainWindow.getLocalizedString("Set state awake, opened eyes"),
        JEDFMainWindow.getLocalizedString("Set state awake, closed eyes"),
        JEDFMainWindow.getLocalizedString("Set artifact"),
        JEDFMainWindow.getLocalizedString("Set state vertex peak"),
        JEDFMainWindow.getLocalizedString("Set state spindle"),
        JEDFMainWindow.getLocalizedString("Set state K complex"),
        JEDFMainWindow.getLocalizedString("Set state Saw Tooth"),
        JEDFMainWindow.getLocalizedString("Duplicate previous state")};
    String[] shortcutsGInfo = {
        "<-",
        "->",
        JEDFMainWindow.getLocalizedString("home key"),
        JEDFMainWindow.getLocalizedString("end key")};
    String[] shortcutsHInfo = {
        "0", //JEDFMainWindow.getLocalizedString("numpad 0"),
        ". | M",
        "1 to 4", //JEDFMainWindow.getLocalizedString("numpad 1 to 4"),
        "5 | R", //JEDFMainWindow.getLocalizedString("numpad 5"),
        "6 | U"}; //JEDFMainWindow.getLocalizedString("numpad 6"),
    String[] shortcutsPSInfo = {
        JEDFMainWindow.getLocalizedString("down"),
        JEDFMainWindow.getLocalizedString("up"),
        JEDFMainWindow.getLocalizedString("space"),
        "7 | O", //JEDFMainWindow.getLocalizedString("numpad 7"),
        "8 | C", //JEDFMainWindow.getLocalizedString("numpad 8"),
        "9 | A", //JEDFMainWindow.getLocalizedString("numpad 9"),
        "P",
        "F | S",
        "K",
        "D | T",
        "+"};
    JPanel generalInfoPanel = new JPanel();
    JPanel jPanelBtnOk = new JPanel();
    JButton jButtonOk = new JButton();
    GridLayout gridLayout1 = new GridLayout();
    JPanel pScorPanel = new JPanel();
    JPanel hypnogramPanel = new JPanel();
    GridLayout gridLayout3 = new GridLayout();
    GridLayout gridLayout4 = new GridLayout();
    BorderLayout borderLayout1 = new BorderLayout();
    JPanel jPanelGlobal = new JPanel();
    BorderLayout borderLayout2 = new BorderLayout();

    public JEDFHelpDialog(ProjetoTCC2View mainWindow) {
        super(mainWindow.getFrame(), true);

        try {
            jbInit();
            setTitle(JEDFMainWindow.getLocalizedString("Keyboard shortcuts"));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        setLabels(generalInfoPanel, contentGInfo, shortcutsGInfo);
        setLabels(hypnogramPanel, contentHInfo, shortcutsHInfo);
        setLabels(pScorPanel, contentPSInfo, shortcutsPSInfo);
        pack();
        setLocationRelativeTo(null);
        setVisible(true);
    }

    private void setLabels(JPanel panel, String[] content, String[] shortcut) {
        for (int i = 0; i < content.length; i++) {
            JLabel jLabel = new JLabel(shortcut[i]);
            jLabel.setHorizontalAlignment(JLabel.RIGHT);
            panel.add(new JLabel(content[i]));
            panel.add(jLabel);
        }
    }

    private void jbInit()
            throws Exception {
        this.getContentPane().setLayout(borderLayout1);
        jButtonOk.setActionCommand("Ok");
        jButtonOk.setHorizontalAlignment(SwingConstants.CENTER);
        jButtonOk.addActionListener(new HelpDialog_jButtonOk_actionAdapter(this));
        generalInfoPanel.setLayout(gridLayout1);
        gridLayout1.setColumns(2);
        gridLayout1.setRows(0);
        gridLayout1.setVgap(2);
        jButtonOk.setText("Ok");
        jPanelBtnOk.setBorder(BorderFactory.createEtchedBorder());
        jPanelBtnOk.setMaximumSize(new Dimension(62, 35));
        hypnogramPanel.setLayout(gridLayout3);
        pScorPanel.setLayout(gridLayout4);
        gridLayout3.setColumns(2);
        gridLayout3.setRows(0);
        gridLayout3.setVgap(2);
        gridLayout4.setColumns(2);
        gridLayout4.setRows(0);
        gridLayout4.setVgap(2);
        jPanelGlobal.setLayout(borderLayout2);
        borderLayout2.setVgap(2);
        generalInfoPanel.setBorder(new TitledBorder(JEDFMainWindow.getLocalizedString(
                "General navigation")));
        hypnogramPanel.setBorder(new TitledBorder(JEDFMainWindow.getLocalizedString(
                "Hypnogram stages")));
        pScorPanel.setBorder(new TitledBorder(JEDFMainWindow.getLocalizedString("Precise scoring")));
        jPanelBtnOk.add(jButtonOk, null);
        jPanelGlobal.add(pScorPanel, java.awt.BorderLayout.SOUTH);
        jPanelGlobal.add(generalInfoPanel, java.awt.BorderLayout.NORTH);
        jPanelGlobal.add(hypnogramPanel, java.awt.BorderLayout.CENTER);
        this.getContentPane().add(jPanelGlobal, java.awt.BorderLayout.NORTH);

        this.getContentPane().add(jPanelBtnOk, java.awt.BorderLayout.SOUTH);

    }

    public void jButtonOk_actionPerformed(ActionEvent e) {
        this.dispose();
    }
}

class HelpDialog_jButtonOk_actionAdapter implements ActionListener {

    private JEDFHelpDialog adaptee;

    HelpDialog_jButtonOk_actionAdapter(JEDFHelpDialog adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButtonOk_actionPerformed(e);
    }
}
